﻿<!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
-->
    
<UserControl
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
  xmlns:common="clr-namespace:System.Windows;assembly=System.Windows.Controls"
  xmlns:system="clr-namespace:System;assembly=mscorlib"
  x:Class="System.Windows.Controls.Samples.TreeViewDataBindingSample">
    <StackPanel>
        <!-- ItemTemplate -->
        <ContentControl Content="ItemTemplate" Style="{StaticResource Header}" />
        <TextBlock Style="{StaticResource Information}">
            The ItemTemplate is a DataTemplate applied to the header of each
            child item of a TreeView or TreeViewItem.
        </TextBlock>
        <controls:TreeView Margin="5">
            <controls:TreeView.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <ContentControl Content="{Binding}" />
                        <ContentControl Foreground="#FF333333" FontSize="9">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="(has " />
                                <ContentControl Content="{Binding Length}" />
                                <TextBlock Text=" characters)" />
                            </StackPanel>
                        </ContentControl>
                    </StackPanel>
                </DataTemplate>
            </controls:TreeView.ItemTemplate>
            
            <system:String>First</system:String>
            <system:String>Second</system:String>
            <system:String>Third</system:String>
        </controls:TreeView>

        <!-- HierarchicalDataTemplate -->
        <ContentControl Content="HierarchicalDataTemplate" Style="{StaticResource Header}" />
        <TextBlock Style="{StaticResource Information}">
            HierarchicalDataTemplates can be used to define the ItemTemplate as
            well as the collection to use for its child items.
        </TextBlock>
        <controls:TreeView x:Name="TreeOfLife" Margin="5">
            <controls:TreeView.ItemTemplate>
                <common:HierarchicalDataTemplate ItemsSource="{Binding Subclasses}">
                    <StackPanel>
                        <TextBlock Text="{Binding Rank}" FontSize="8" FontStyle="Italic" Foreground="Gray" Margin="0 0 0 -5" />
                        <TextBlock Text="{Binding Classification}" />
                    </StackPanel>
                </common:HierarchicalDataTemplate>
            </controls:TreeView.ItemTemplate>
        </controls:TreeView>

        <src:SourceViewer xmlns:src="clr-namespace:System.Windows.Controls.Samples;assembly=System.Windows.Controls.Samples.Common" xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <src:SourceFile Path="TreeViewDataBindingSample.xaml">
    <src:SourceFile.Source>
      <sys:String>&lt;!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
--&gt;
    
&lt;UserControl
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
  xmlns:common="clr-namespace:System.Windows;assembly=System.Windows.Controls"
  xmlns:system="clr-namespace:System;assembly=mscorlib"
  x:Class="System.Windows.Controls.Samples.TreeViewDataBindingSample"&gt;
    &lt;StackPanel&gt;
        &lt;!-- ItemTemplate --&gt;
        &lt;ContentControl Content="ItemTemplate" Style="{StaticResource Header}" /&gt;
        &lt;TextBlock Style="{StaticResource Information}"&gt;
            The ItemTemplate is a DataTemplate applied to the header of each
            child item of a TreeView or TreeViewItem.
        &lt;/TextBlock&gt;
        &lt;controls:TreeView Margin="5"&gt;
            &lt;controls:TreeView.ItemTemplate&gt;
                &lt;DataTemplate&gt;
                    &lt;StackPanel&gt;
                        &lt;ContentControl Content="{Binding}" /&gt;
                        &lt;ContentControl Foreground="#FF333333" FontSize="9"&gt;
                            &lt;StackPanel Orientation="Horizontal"&gt;
                                &lt;TextBlock Text="(has " /&gt;
                                &lt;ContentControl Content="{Binding Length}" /&gt;
                                &lt;TextBlock Text=" characters)" /&gt;
                            &lt;/StackPanel&gt;
                        &lt;/ContentControl&gt;
                    &lt;/StackPanel&gt;
                &lt;/DataTemplate&gt;
            &lt;/controls:TreeView.ItemTemplate&gt;
            
            &lt;system:String&gt;First&lt;/system:String&gt;
            &lt;system:String&gt;Second&lt;/system:String&gt;
            &lt;system:String&gt;Third&lt;/system:String&gt;
        &lt;/controls:TreeView&gt;

        &lt;!-- HierarchicalDataTemplate --&gt;
        &lt;ContentControl Content="HierarchicalDataTemplate" Style="{StaticResource Header}" /&gt;
        &lt;TextBlock Style="{StaticResource Information}"&gt;
            HierarchicalDataTemplates can be used to define the ItemTemplate as
            well as the collection to use for its child items.
        &lt;/TextBlock&gt;
        &lt;controls:TreeView x:Name="TreeOfLife" Margin="5"&gt;
            &lt;controls:TreeView.ItemTemplate&gt;
                &lt;common:HierarchicalDataTemplate ItemsSource="{Binding Subclasses}"&gt;
                    &lt;StackPanel&gt;
                        &lt;TextBlock Text="{Binding Rank}" FontSize="8" FontStyle="Italic" Foreground="Gray" Margin="0 0 0 -5" /&gt;
                        &lt;TextBlock Text="{Binding Classification}" /&gt;
                    &lt;/StackPanel&gt;
                &lt;/common:HierarchicalDataTemplate&gt;
            &lt;/controls:TreeView.ItemTemplate&gt;
        &lt;/controls:TreeView&gt;
    &lt;/StackPanel&gt;
&lt;/UserControl&gt;</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="TreeViewDataBindingSample.xaml.cs">
    <src:SourceFile.Source>
      <sys:String>// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;

namespace System.Windows.Controls.Samples
{
    /// &lt;summary&gt;
    /// Sample demonstrating TreeView data-binding.
    /// &lt;/summary&gt;
    [Sample("(4)Data Binding", DifficultyLevel.Basic)]
    [Category("TreeView")]
    public partial class TreeViewDataBindingSample : UserControl
    {
        /// &lt;summary&gt;
        /// Initializes a new instance of the TreeViewDataBindingSample class.
        /// &lt;/summary&gt;
        public TreeViewDataBindingSample()
        {
            InitializeComponent();

            // Fill the tree with data
            TreeOfLife.ItemsSource = Taxonomy.Life;
        }
    }
}</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="TreeViewDataBindingSample.xaml.vb">
    <src:SourceFile.Source>
      <sys:String>' (c) Copyright Microsoft Corporation.
' This source is subject to the Microsoft Public License (Ms-PL).
' Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
' All other rights reserved.

Imports Microsoft.VisualBasic
Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.ComponentModel

''' &lt;summary&gt;
''' Sample demonstrating TreeView data-binding.
''' &lt;/summary&gt;
&lt;Sample("(4)Data Binding", DifficultyLevel.Basic), Category("TreeView")&gt; _
Partial Public Class TreeViewDataBindingSample
    Inherits UserControl
    ''' &lt;summary&gt;
    ''' Initializes a new instance of the TreeViewDataBindingSample class.
    ''' &lt;/summary&gt;
    &lt;System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification:="InitializeComponent Required by Visual Studio.")&gt; _
    Public Sub New()
        InitializeComponent()

        ' Fill the tree with data
        TreeOfLife.ItemsSource = Taxonomy.Life
    End Sub
End Class
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
</src:SourceViewer>
    </StackPanel>
</UserControl>